<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <router-link tag="button" to="/home">首页</router-link>
    <router-link tag="button" to="/news">新闻页</router-link>
    <router-link tag="button" replace to="/about">关于我们</router-link>
    <hr>
    <router-view></router-view>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>
    // 定义好路由组件的options
    const Home = {
      template: `
        <div>
          <h2>我是home页</h2>
        </div>
      `
    }
    const News = {
      template: `
        <div>
          <h2>我是news页</h2>
        </div>
      `
    }
    const About = {
      template: `
        <div>
          <h2>我是about页</h2>
        </div>
      `
    }
    const NotFound = {
      template: `
        <div>
          <h2>我是404页</h2>
        </div>
      `
    }
    const routes = [
      {
        path: '/',
        redirect: '/home'
      },
      {
        path: '/home',
        name: '首页',
        component: Home
      },
      {
        path: '/news',
        name: '新闻页',
        component: News
      },
      {
        path: '/about',
        name: '关于我们',
        component: About
      },
      {
        path: '*',
        name: '404',
        component: NotFound
      }
    ]
    const router = new VueRouter({
      routes
    })
    const vm = new Vue({
      el: '#app',
      router
    })
  </script>
</body>
</html>